﻿using System.Web.Mvc;
using Quick.Common.Plugin;
using Quick.PluginFramework.ViewEngines;
using Quick.Common;


//[assembly: System.Web.PreApplicationStartMethod(typeof(Bootstrapper), "Initialize")]

namespace Quick.PluginFramework
{
    /// <summary>
    /// 引导程序。
    /// </summary>
    public static class Bootstrapper
    {
        static Bootstrapper()
        {
        }

        /// <summary>
        /// 初始化。
        /// </summary>
        public static void Initialize()
        {
            Configuration.Instance.SetDefault<IExtensionMessage, ExtensionMessage>(new ExtensionMessage());

            //注册插件控制器工厂。
            ControllerBuilder.Current.SetControllerFactory(new PluginControllerFactory());

            //注册插件模板引擎。
            System.Web.Mvc.ViewEngines.Engines.Clear();
            System.Web.Mvc.ViewEngines.Engines.Add(new ThemeableRazorViewEngine() { CurrentTheme = httpContext => httpContext.Session["theme"] as string ?? string.Empty });

            //初始化插件。
            PluginManager.Initialize();

            //启动插件检测器。
            PluginWatcher.Start();
        }
    }
}